<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得结果数据</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-result" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_result</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_result</span> &mdash; <span class="dc-title">取得结果数据</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.mysql-result-unknown-seealsp">
    <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="methodname"><strong>mysql_result</strong></span>
      ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
     , <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
     [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$field</code></span>
    ] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>mysql_result()</strong></span> 返回 MySQL
     结果集中一个单元的内容。字段参数可以是字段的偏移量或者字段名，或者是字段表点字段名（tablename.fieldname）。如果给列起了别名（&#039;select
     foo as bar from...&#039;），则用别名替代列名。
    </p>
    <p class="para">
     当作用于很大的结果集时，应该考虑使用能够取得整行的函数（在下边指出）。这些函数在一次函数调用中返回了多个单元的内容，比
     <span class="function"><strong>mysql_result()</strong></span>
     快得多。此外注意在字段参数中指定数字偏移量比指定字段名或者
     tablename.fieldname 要快得多。
    </p>
    <p class="para">
     调用 <span class="function"><strong>mysql_result()</strong></span>
     不能和其它处理结果集的函数混合调用。
    </p>
    <p class="para">
     <div class="example" id="example-2166">
      <p><strong>Example #1 <span class="function"><strong>mysql_result()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;name&nbsp;FROM&nbsp;work.employee"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;query:&nbsp;.&nbsp;mysql_error());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;mysql_result(</span><span style="color: #0000BB">$result</span><span style="color: #DD0000">,2);&nbsp;//&nbsp;outputs&nbsp;third&nbsp;employee's&nbsp;name<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;mysql_close(</span><span style="color: #0000BB">$link</span><span style="color: #DD0000">);<br />?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
    <p class="para">
     推荐使用高性能的替代函数：<span class="function"><a href="mysql_fetch_row.html" class="function">mysql_fetch_row()</a></span>，<span class="function"><a href="mysql_fetch_array.html" class="function">mysql_fetch_array()</a></span>，<span class="function"><a href="mysql_fetch_assoc.html" class="function">mysql_fetch_assoc()</a></span>
     和 <span class="function"><a href="mysql_fetch_object.html" class="function">mysql_fetch_object()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>